home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pwxms.zip / XMS.ASM < prev    next >
Assembly Source File  |  1993-01-04  |  18KB  |  526 lines

  1. ;
  2. ; XMS.ASM - External Assembler Routines for XMS.PAS
  3. ;
  4. ; Paul Willmott
  5. ;
  6. ; 1.1 - 24.07.89
  7. ;
  8.  
  9. .MODEL TPASCAL
  10.  
  11. .DATA
  12.  
  13.                                       EXTRN XMSControl : DWORD
  14.                                       EXTRN XMSStatus  : BYTE
  15.  
  16. DATA                                  ENDS
  17.  
  18. .CODE
  19.  
  20. ;
  21. ; This MACRO Handles the Setting of XMSStatus after All Operations
  22. ;
  23.  
  24. SetXMSStatus                          MACRO
  25.                                            LOCAL Fail
  26.                                            CMP AX,0000H
  27.                                            JE Fail
  28.                                            XOR BL,BL
  29. Fail:                                      MOV XMSStatus,BL
  30.                                       ENDM
  31.  
  32. ;
  33. ; This Function is called by default if the program hasn't called
  34. ; _XMSInstalled or if no XMS driver is found.
  35. ;
  36.  
  37. _XMSNotInitialised                    PROC FAR
  38.                                       PUBLIC _XMSNotInitialised
  39.  
  40.                                       XOR AX,AX
  41.                                       MOV BL,80H
  42.                                       RET
  43.  
  44. _XMSNotInitialised                    ENDP
  45.  
  46. ;
  47. ; FUNCTION _XMSInstalled:BYTE
  48. ;
  49. ; This Function Returns 80h iff Driver Is Installed
  50. ;
  51.  
  52. _XMSInstalled                         PROC NEAR
  53.                                       PUBLIC _XMSInstalled
  54.  
  55. ;
  56. ;    Check XMS Driver Installed
  57. ;
  58.  
  59.                                       MOV AX,4300H
  60.                                       INT 2FH
  61.                                       CMP AL,80H
  62.                                       JNE NoXMSDriver
  63.  
  64. ;
  65. ;    Get the Address of the XMS Driver's Control Function
  66. ;
  67.  
  68.                                       MOV AX,4310H
  69.                                       INT 2FH
  70.                                       MOV WORD PTR [XMSControl],BX
  71.                                       MOV WORD PTR [XMSControl+2],ES
  72.  
  73. ;
  74. ;    Set Return Value
  75. ;
  76.  
  77.                                       MOV AL,80H
  78.  
  79. NoXMSDriver:                          RET
  80.  
  81. _XMSInstalled                         ENDP
  82.  
  83. ;
  84. ; FUNCTION _XMSVersionNumber:WORD
  85. ;
  86. ; This Function Returns a 16-Bit BCD Number representing the revision
  87. ; of the DOS Extended Memory Specification which the Driver implements.
  88. ;
  89.  
  90. _XMSVersionNumber                     PROC NEAR
  91.                                       PUBLIC _XMSVersionNumber
  92.  
  93.                                       MOV AH,00H
  94.                                       CALL [XMSControl]
  95.                                       MOV XMSStatus,00H
  96.                                       RET
  97.  
  98. _XMSVersionNumber                     ENDP
  99.  
  100. ;
  101. ; FUNCTION _XMSInternalRevisionNumber:WORD
  102. ;
  103. ; This Function Returns a 16-Bit BCD Number representing the driver's
  104. ; internal revision number.
  105. ;
  106.  
  107. _XMSDriverInternalRevisionNumber      PROC NEAR
  108.                                       PUBLIC _XMSDriverInternalRevisionNumber
  109.  
  110.                                       MOV AH,00H
  111.                                       CALL [XMSControl]
  112.                                       MOV AX,BX
  113.                                       MOV XMSStatus,00H
  114.                                       RET
  115.  
  116. _XMSDriverInternalRevisionNumber      ENDP
  117.  
  118. ;
  119. ; FUNCTION _XMSHMAExists:WORD
  120. ;
  121. ; This Function Returns 0001H if the HMA exists, 0000H otherwise.
  122. ;
  123.  
  124. _XMSHMAExists                         PROC NEAR
  125.                                       PUBLIC _XMSHMAExists
  126.  
  127.                                       MOV AH,00H
  128.                                       CALL [XMSControl]
  129.                                       MOV AX,DX
  130.                                       MOV XMSStatus,00H
  131.                                       RET
  132.  
  133. _XMSHMAExists                         ENDP
  134.  
  135. ;
  136. ; PROCEDURE XMSRequestHMA
  137. ;
  138. ; This procedure attempts to reserve the 64K-16 byte high memory area
  139. ; for the caller.
  140. ;
  141.  
  142. XMSRequestHMA                         PROC FAR
  143.                                       PUBLIC XMSRequestHMA
  144.  
  145.                                       MOV AH,01H
  146.                                       MOV DX,0FFFFH
  147.                                       CALL [XMSControl]
  148.                                       SetXMSStatus
  149.                                       RET
  150.  
  151. XMSRequestHMA                         ENDP
  152.  
  153. ;
  154. ; PROCEDURE XMSReleaseHMA
  155. ;
  156. ; This procedure releases the high memory area and allows other programs
  157. ; to use it. Programs which use the HMA must release it before exiting.
  158. ; When the HMA has been released, any code or data stored in it becomes
  159. ; invalid and should not be accessed.
  160. ;
  161.  
  162. XMSReleaseHMA                         PROC FAR
  163.                                       PUBLIC XMSReleaseHMA
  164.  
  165.                                       MOV AH,02H
  166.                                       CALL [XMSControl]
  167.                                       SetXMSStatus
  168.                                       RET
  169.  
  170. XMSReleaseHMA                         ENDP
  171.  
  172. ;
  173. ; PROCEDURE XMSGlobalEnableA20
  174. ;
  175. ; This procedure attempts to enable the A20 line. It should only be used
  176. ; by programs which have control of the HMA. The A20 line should be turned
  177. ; off before a program releases control of the system.
  178. ;
  179.  
  180. XMSGlobalEnableA20                    PROC FAR
  181.                                       PUBLIC XMSGlobalEnableA20
  182.  
  183.                                       MOV AH,03H
  184.                                       CALL [XMSControl]
  185.                                       SetXMSStatus
  186.                                       RET
  187.  
  188. XMSGlobalEnableA20                    ENDP
  189.  
  190. ;
  191. ; PROCEDURE XMSGlobalDisableA20
  192. ;
  193. ; This function attempts to disable the A20 line. It should only be used
  194. ; by programs which have control of the HMA. The A20 line should be
  195. ; disabled before a program releases control of the system.
  196. ;
  197.  
  198. XMSGlobalDisableA20                   PROC FAR
  199.                                       PUBLIC XMSGlobalDisableA20
  200.  
  201.                                       MOV AH,04H
  202.                                       CALL [XMSControl]
  203.                                       SetXMSStatus
  204.                                       RET
  205.  
  206. XMSGlobalDisableA20                   ENDP
  207.  
  208. ;
  209. ; PROCEDURE XMSLocalEnableA20
  210. ;
  211. ; This procedure attempts to enable the A20 line. It should only be used
  212. ; by programs which need direct access to extended memory.
  213. ;
  214.  
  215. XMSLocalEnableA20                     PROC FAR
  216.                                       PUBLIC XMSLocalEnableA20
  217.  
  218.                                       MOV AH,05H
  219.                                       CALL [XMSControl]
  220.                                       SetXMSStatus
  221.                                       RET
  222.  
  223. XMSLocalEnableA20                     ENDP
  224.  
  225. ;
  226. ; PROCEDURE XMSLocalDisableA20
  227. ;
  228. ; This procedure attempts to Disable the A20 line. It should only be used
  229. ; by programs which need direct access to extended memory.
  230. ;
  231.  
  232. XMSLocalDisableA20                    PROC FAR
  233.                                       PUBLIC XMSLocalDisableA20
  234.  
  235.                                       MOV AH,06H
  236.                                       CALL [XMSControl]
  237.                                       SetXMSStatus
  238.                                       RET
  239.  
  240. XMSLocalDisableA20                    ENDP
  241.  
  242. ;
  243. ; FUNCTION _XMSQueryA20
  244. ;
  245. ; This function returns 0001H if the A20 line is physically enabled,
  246. ; 0000H otherwise.
  247. ;
  248.  
  249. _XMSQueryA20                          PROC NEAR
  250.                                       PUBLIC _XMSQueryA20
  251.  
  252.                                       MOV AH,07H
  253.                                       CALL [XMSControl]
  254.                                       SetXMSStatus
  255.                                       RET
  256.  
  257. _XMSQueryA20                          ENDP
  258.  
  259. ;
  260. ; FUNCTION XMSLargestFreeEMB:WORD
  261. ;
  262. ; This function returns the largest free extended memory block in K-bytes.
  263. ;
  264.  
  265. XMSLargestFreeEMB                     PROC FAR
  266.                                       PUBLIC XMSLargestFreeEMB
  267.  
  268.                                       MOV AH,08H
  269.                                       CALL [XMSControl]
  270.                                       SetXMSStatus
  271.                                       RET
  272.  
  273. XMSLargestFreeEMB                     ENDP
  274.  
  275.  
  276. ;
  277. ; FUNCTION XMSTotalFreeEM:WORD
  278. ;
  279. ; This function returns the Total amount of free extended memory block
  280. ; in K-bytes.
  281. ;
  282.  
  283. XMSTotalFreeEM                        PROC FAR
  284.                                       PUBLIC XMSTotalFreeEM
  285.  
  286.                                       MOV AH,08H
  287.                                       CALL [XMSControl]
  288.                                       SetXMSStatus
  289.                                       MOV AX,DX
  290.                                       RET
  291.  
  292. XMSTotalFreeEM                        ENDP
  293.  
  294. ;
  295. ; FUNCTION XMSAllocEMB(Amount:WORD):WORD
  296. ;
  297. ; This function attempts to allocate a block of the given size out of the
  298. ; pool of free extended memory. If a block is availiable, it is reserved
  299. ; for the caller and a 16-bit handle to that block is returned. The handle
  300. ; returned should be used in all subsequent extended memory calls. If no
  301. ; memory was allocated, the returned handle is null.
  302. ;
  303.  
  304. XMSAllocEMB                           PROC FAR Amount:WORD
  305.                                       PUBLIC XMSAllocEMB
  306.  
  307.                                       MOV AH,09H
  308.                                       MOV DX,Amount
  309.                                       CALL [XMSControl]
  310.                                       CMP AX,0001H
  311.                                       JNE L1
  312.                                       MOV AX,DX
  313.                                       XOR BL,BL
  314. L1:                                   MOV XMSStatus,BL
  315.                                       RET
  316.  
  317. XMSAllocEMB                           ENDP
  318.  
  319. ;
  320. ; PROCEDURE XMSFreeEMB(Handle:WORD)
  321. ;
  322. ; This procedure frees a block of extended memory. Programs which allocate
  323. ; extended memory should free their memory blocks before exiting. When
  324. ; an extended memory buffer is freed, its handle and all data stored in
  325. ; it become invalid and should not be accessed.
  326. ;
  327.  
  328. XMSFreeEMB                            PROC FAR Handle:WORD
  329.                                       PUBLIC XMSFreeEMB
  330.  
  331.                                       MOV AH,0AH
  332.                                       MOV DX,Handle
  333.                                       CALL [XMSControl]
  334.                                       SetXMSStatus
  335.                                       RET
  336.  
  337. XMSFreeEMB                            ENDP
  338.  
  339. ;
  340. ; PROCEDURE _XMSMoveEMB(ExtMemStructPtr:POINTER) ;
  341. ;
  342. ; This function attempts to transfer a block of data from one location
  343. ; to another. (see XMS.PAS)
  344. ;
  345.  
  346. _XMSMoveEMB                           PROC NEAR ExtMemStructPtr:DWORD
  347.                                       PUBLIC _XMSMoveEMB
  348.  
  349.                                       LDS SI,ExtMemStructPtr
  350.                                       MOV AH,0BH
  351.                                       CALL [XMSControl]
  352.                                       SetXMSStatus
  353.                                       RET
  354.  
  355. _XMSMoveEMB                           ENDP
  356.  
  357. ;
  358. ; PROCEDURE _XMSLockEMB(Handle:WORD)
  359. ;
  360. ; This function locks an extended memory block and returns its base address
  361. ; as a 32-bit linear address. Locked blocks are guaranteed not to move. The
  362. ; 32-bit pointer is only valid while the block is locked. Locked blocks
  363. ; should be unlocked as soon as possible.
  364. ;
  365.  
  366. XMSLockEMB                            PROC FAR Handle:WORD
  367.                                       PUBLIC XMSLockEMB
  368.  
  369.                                       MOV AH,0CH
  370.                                       MOV DX,Handle
  371.                                       CALL [XMSControl]
  372.                                       CMP AX,0001H
  373.                                       JNE L2
  374.                                       MOV AX,BX
  375.                                       XOR BL,BL
  376. L2:                                   MOV XMSStatus,BL
  377.                                       RET
  378.  
  379. XMSLockEMB                            ENDP
  380.  
  381. ;
  382. ; PROCEDURE XMSUnLockEMB(Handle:WORD)
  383. ;
  384. ; This procedure unlocks a locked extended memory block. Any 32-Bit
  385. ; pointers into the block become invalid and should no longer be used.
  386. ;
  387.  
  388. XMSUnLockEMB                          PROC FAR Handle:WORD
  389.                                       PUBLIC XMSUnLockEMB
  390.  
  391.                                       MOV AH,0DH
  392.                                       MOV DX,Handle
  393.                                       CALL [XMSControl]
  394.                                       SetXMSStatus
  395.                                       RET
  396.  
  397. XMSUnLockEMB                          ENDP
  398.  
  399. ;
  400. ; FUNCTION XMSGetEMBLockCount(Handle:WORD):BYTE
  401. ;
  402. ; This Function returns the Block's Lock Count
  403.  
  404. XMSGetEMBLockCount                    PROC FAR Handle:WORD
  405.                                       PUBLIC XMSGetEMBLockCount
  406.  
  407.                                       MOV AH,0EH
  408.                                       MOV DX,Handle
  409.                                       CALL [XMSControl]
  410.                                       CMP AX,0001H
  411.                                       JNE L3
  412.                                       MOV AL,BH
  413.                                       XOR BL,BL
  414. L3:                                   MOV XMSStatus,BL
  415.                                       RET
  416.  
  417. XMSGetEMBLockCount                    ENDP
  418.  
  419. ;
  420. ; FUNCTION XMSGetFreeEMBHandles(Handle:WORD):BYTE
  421. ;
  422. ; This Function returns the Number of free EMB Handles in system.
  423.  
  424. XMSGetFreeEMBHandles                  PROC FAR Handle:WORD
  425.                                       PUBLIC XMSGetFreeEMBHandles
  426.  
  427.                                       MOV AH,0EH
  428.                                       MOV DX,Handle
  429.                                       CALL [XMSControl]
  430.                                       CMP AX,0001H
  431.                                       JNE L4
  432.                                       MOV AL,BL
  433.                                       XOR BL,BL
  434. L4:                                   MOV XMSStatus,BL
  435.                                       RET
  436.  
  437. XMSGetFreeEMBHandles                  ENDP
  438.  
  439. ;
  440. ; FUNCTION XMSGetEMBLength(Handle:WORD):WORD
  441. ;
  442. ; This Function returns the block's length in K-Bytes.
  443.  
  444. XMSGetEMBLength                       PROC FAR Handle:WORD
  445.                                       PUBLIC XMSGetEMBLength
  446.  
  447.                                       MOV AH,0EH
  448.                                       MOV DX,Handle
  449.                                       CALL [XMSControl]
  450.                                       CMP AX,0001H
  451.                                       JNE L5
  452.                                       MOV AX,DX
  453.                                       XOR BL,BL
  454. L5:                                   MOV XMSStatus,BL
  455.                                       RET
  456.  
  457. XMSGetEMBLength                       ENDP
  458.  
  459. ;
  460. ; PROCEDURE XMSReAllocEMB(Handle,NewSize:WORD)
  461. ;
  462. ; This procedure attempts to reallocate an unlocked memory block so that
  463. ; it becomes the newly specified size. If the new size is smaller than
  464. ; the old block's size, all data at the upper end of the old block is lost
  465. ;
  466.  
  467. XMSReAllocEMB                         PROC FAR Handle,NewSize:WORD
  468.                                       PUBLIC XMSReAllocEMB
  469.  
  470.                                       MOV AH,0FH
  471.                                       MOV DX,Handle
  472.                                       MOV BX,NewSize
  473.                                       CALL [XMSControl]
  474.                                       SetXMSStatus
  475.                                       RET
  476.  
  477. XMSReAllocEMB                         ENDP
  478.  
  479. ;
  480. ; FUNCTION XMSRequestUMB(VAR Amount:WORD):WORD
  481. ;
  482. ; This function attempts to allocate an upper memory block to the caller.
  483. ; if the function fails, the size of the largest free UMB is returned in
  484. ; Amount otherwise the actual size of the block is returned.
  485. ; The function returns the segment number of the UMB.
  486. ;
  487.  
  488. XMSRequestUMB                         PROC FAR Amount:PTR WORD
  489.                                       PUBLIC XMSRequestUMB
  490.  
  491.                                       MOV AH,10H
  492.                                       MOV DX,[Amount]
  493.                                       CALL [XMSControl]
  494.                                       MOV [Amount],DX
  495.                                       CMP AX,0001H
  496.                                       JNE L6
  497.                                       MOV AX,BX
  498.                                       XOR BL,BL
  499. L6:                                   MOV XMSStatus,BL
  500.                                       RET
  501.  
  502. XMSRequestUMB                         ENDP
  503.  
  504. ;
  505. ; PROCEDURE XMSReleaseUMB(SegmentNumber:WORD)
  506. ;
  507. ; This procedure frees a previously allocated upper memory block. When an
  508. ; UMB has been released, any code or data stored in it becomes invalid and
  509. ; should not be accessed.
  510. ;
  511.  
  512. XMSReleaseUMB                         PROC FAR SegmentNumber:WORD
  513.                                       PUBLIC XMSReleaseUMB
  514.  
  515.                                       MOV AH,11H
  516.                                       MOV DX,SegmentNumber
  517.                                       CALL [XMSControl]
  518.                                       SetXMSStatus
  519.                                       RET
  520.  
  521. XMSReleaseUMB                         ENDP
  522.  
  523.                                       ENDS
  524.  
  525.                                       END
  526.